<template>
  <view class="wrap" :style="colorStyle">
    <view
      class="top_box flex_fc"
      :style="{ 'background-image': `url(${top_background_img})` }"
    >
      <!-- <view class="logo">
        <image :src="userInfo.logo" mode="scaleToFill" v-if="userInfo.logo" />
        <image src="@/static/image/logo.png" mode="scaleToFill" v-else />
      </view> -->
      <view class="title">
        <text v-if="userInfo.enterprise_name">{{
          userInfo.enterprise_name
        }}</text>
        <text v-else>暂无名称</text>
      </view>
      <view
        class="edit_box pad1030"
        @click="JumpPath('/pages/accountSet/companyInformation')"
      >
        <text class="iconfont icon-bianji"></text>
        编辑
      </view>
    </view>
    <view class="menu_box" style="margin-top: -60rpx">
      <view class="title_box">基本工具</view>
      <view class="list_box">
        <view
          class="list_item flex_fc"
          v-for="(item, index) in basicMenu"
          :key="index"
          @click="clickHandler(item)"
        >
          <image class="menu_img" :src="item.icon" mode="scaleToFill" />
          <text>{{ item.name }}</text>
        </view>
      </view>
    </view>
    <view class="menu_box">
      <view class="title_box">账号设置</view>
      <view class="list_box">
        <view
          class="list_item flex_fc"
          v-for="(item, index) in setMenu"
          :key="index"
          @click="clickHandler(item)"
        >
          <image class="menu_img" :src="item.icon" mode="scaleToFill" />
          <text>{{ item.name }}</text>
        </view>
      </view>
    </view>
    <up-popup :show="show" @close="close" @open="open" round="20">
      <view class="tip_pop">
        <view class="pop_title">公告设置</view>
        <view class="info_box flex_sb">
          <view class="textarea_box">
            <textarea
              class="textarea_class"
              placeholder-class="placeholder_class"
              placeholder="请输入公告内容"
              v-model="notice_content"
            ></textarea>
          </view>
        </view>
        <view class="theme_btn" @click="setNoticeDebounce">保存</view>
      </view>
    </up-popup>
    <view class="uni-p-b-98"></view>
    <pageFooter
      :isShowAllMenu="true"
      :is_money_remind="is_money_remind"
      :selected="5"
    ></pageFooter>
  </view>
</template>

<script setup lang="ts">
import pageFooter from "@/components/pageFooter/index.vue";
import { getUserInfo, setRemind } from "@/api/user";
import { useTheme } from "@/composables/useTheme";
import { JumpPath, Tips } from "@/utils";
import { debounceImmediate } from "@/utils/validate";
import { checkLogin, toLogin } from "@/libs/login";
import { onLoad, onShow } from "@dcloudio/uni-app";
import saveUserInfoToLocation from "@/composables/saveUserInfoToLocation";
import Cache from "@/utils/cache";
import { LOGIN_STATUS, LOGIN_BUSIN_STATUS } from "@/config/cache.js";
import { setNotice } from "@/api/setting";
import wx from "weixin-js-sdk";
const userInfo = ref<any>({
  logo: "",
  enterprise_name: "",
});
onShow(() => {
  setShareHandler();
  if (checkLogin()) {
    getUserInfoHandler();
  } else {
    toLogin();
  }
});
let is_money_remind = ref(false); //到价提醒展示
const getPriceRemindDebounce = debounceImmediate(getPriceRemind, 500);
// 到价提醒接口
function getPriceRemind() {
  const params = {
    is_money_remind: tipSwitch.value ? 1 : 0,
  };
  setRemind(params).then((res: any) => {
    Tips({ title: res.info });
    close();
    is_money_remind.value = !!res.data.business.is_money_remind;
    saveUserInfoToLocation(res.data.business);
  });
}
let top_background_img = ref("");
function getUserInfoHandler() {
  getUserInfo().then((res: any) => {
    userInfo.value = res.data.business;
    top_background_img.value = res.data.top_background_img;
    tipSwitch.value = !!res.data.business.is_money_remind;
    is_money_remind.value = !!res.data.business.is_money_remind;
    notice_content.value = userInfo.value.notice_content; //公告回显
    saveUserInfoToLocation(res.data.business);
  });
}
const { colorStyle } = useTheme();
let tipSwitch = ref(true);
function clickHandler(item: any) {
  if (item.name == "退出登录") {
    uni.showModal({
      title: "提示",
      content: "确定要退出登录吗？",
      success: function (res) {
        if (res.confirm) {
          Tips({ title: "退出成功" });
          Cache.clear(LOGIN_BUSIN_STATUS);
          uni.reLaunch({
            url: "/pages/users/login",
          });
        }
      },
    });

    return;
  }
  if (item.name == "公告设置") return open();
  if (item.path) {
    JumpPath(item.path);
  } else {
    // 联系我们
    uni.makePhoneCall({
      phoneNumber: "13652335620",
    });
  }
}
let basicMenu = ref([
  {
    name: "行情管理",
    icon: "/static/image/menu7.png",
    path: "/pages/basicSet/channelData",
  },
  {
    name: "品类报价",
    icon: "/static/image/menu4.png",
    path: "/pages/basicSet/quotationManagement",
  },
  {
    name: "营业时间",
    icon: "/static/image/_menu3.png",
    path: "/pages/accountSet/businessHours",
  },
  {
    name: "主题颜色",
    icon: "/static/image/menu2.png",
    path: "/pages/basicSet/themeSet",
  },
  {
    name: "分享海报",
    icon: "/static/image/menu6.png",
    path: "/pages/basicSet/posterSet",
  },
  {
    name: "公告设置",
    icon: "/static/image/menu5.png",
    path: "",
  },
  {
    name: "显示设置",
    icon: "/static/image/menu3.png",
    path: "/pages/basicSet/showSet",
  },
  {
    name: "大屏报价",
    icon: "/static/image/menu8.png",
    path: "/pages/basicSet/largeScreen",
  },
  // {
  //   name: "公告设置",
  //   icon: "/static/image/menu1.png",
  //   path: "/pages/basicSet/noticeSet",
  // },
]);
let setMenu = ref([
  {
    name: "企业信息",
    icon: "/static/image/_menu1.png",
    path: "/pages/accountSet/companyInformation",
  },
  {
    name: "重置密码",
    icon: "/static/image/_menu2.png",
    path: "/pages/users/forget",
  },

  {
    name: "平台客服",
    icon: "/static/image/_menu4.png",
    path: "",
  },
  {
    name: "退出登录",
    icon: "/static/image/_menu5.png",
    path: "",
  },
]);
// 创建响应式数据
const show = ref(false);

// 定义方法
function open() {
  // 打开逻辑，比如设置 show 为 true
  show.value = true;
  // console.log('open');
}

function close() {
  // 关闭逻辑，设置 show 为 false
  show.value = false;
  // console.log('close');
}
function switch1Change(e: any) {
  console.log("switch1 发生 change 事件，携带值为", tipSwitch.value);
}

function setShareHandler() {
  wx.ready(() => {
    wx.showAllNonBaseMenuItem();
    wx.hideMenuItems({
      menuList: ["menuItem:copyUrl"], // 屏蔽复制链接
    });
  });
}

// 公告设置start----------
let notice_content = ref("");
const setNoticeDebounce = debounceImmediate(setNoticeHandler, 500);
function setNoticeHandler() {
  let params = { notice_content: notice_content.value };
  setNotice(params).then((res) => {
    close();
    Tips({ title: res.info });
    saveUserInfoToLocation(res.data.business);
  });
  console.log("确认点击");
}
// 公告设置end----------
</script>

<style scoped lang="scss">
.wrap {
  // padding-top: 65rpx;
  min-height: 100vh;
  background-image: radial-gradient(
    at top,
    rgba(207, 214, 217, 1),
    rgba(234, 232, 221, 1) 10%,
    rgba(250, 249, 244, 1) 50%,
    rgba(214, 221, 222, 1) 100%
  );
  .tip_pop {
    padding: 50rpx 0;
    background: rgba(248, 248, 248, 1);
    .pop_title {
      color: rgba(46, 46, 46, 1);
      font-size: 34rpx;
      font-weight: 600;
      margin-bottom: 50rpx;
      text-align: center;
    }
    .info_box {
      padding: 10rpx 30rpx;
      background: #fff;
      font-size: 30rpx;
      margin-bottom: 30rpx;
      .textarea_box {
        width: 100%;
        height: 200rpx;
        overflow: hidden;
        background: #fff;
        textarea {
          font-size: 30rpx;
        }
        .textarea_class {
          height: 200rpx;
          width: 100%;
        }
        .placeholder_class {
          color: #ccc;
        }
      }
    }
    .tip_text {
      padding: 0rpx 30rpx;
      font-size: 28rpx;
      color: rgba(125, 136, 140, 1);
      margin-bottom: 60rpx;
    }
  }
  .menu_box {
    width: 700rpx;
    margin: 0 auto 30rpx;
    border-radius: 10rpx;
    background: rgba(255, 255, 255, 1);
    .title_box {
      width: 100%;
      height: 90rpx;
      line-height: 90rpx;

      padding-left: 25rpx;
      border-bottom: 2rpx solid rgba(241, 245, 247, 1);
    }
    .list_box {
      padding: 40rpx 20rpx;
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 30rpx;
      .list_item {
        font-size: 28rpx;
        color: rgba(67, 74, 84, 1);
        .menu_img {
          display: block;
          width: 48rpx;
          height: 48rpx;
          margin-bottom: 20rpx;
        }
      }
    }
  }
  .top_box {
    height: 382rpx;
    width: 100%;
    // margin-bottom: 50rpx;
    background-size: 100% 100%;
    background-repeat: no-repeat;

    .logo {
      width: 150rpx;
      height: 150rpx;
      margin-bottom: 30rpx;
      image {
        width: 100%;
        height: 100%;
      }
    }
    .title {
      font-size: 50rpx;
      font-weight: 600;
      color: var(--view-tabale-title);
      margin-bottom: 16rpx;
    }
    .edit_box {
      color: rgba(63, 64, 66, 1);
      font-size: 24rpx;
      border-radius: 999rpx;
      background: rgba(255, 255, 255, 1);
      .iconfont {
        font-size: 24rpx;
        color: rgba(63, 64, 66, 1);
      }
    }
  }
}
</style>
